package com.mabang.medata.client;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.xml.rpc.encoding.XMLType;

import org.apache.log4j.Logger;

import com.mabang.medata.procotol.BillProcotol;
import com.mabang.medata.procotol.QuoteProcotol;
import com.mabang.medata.util.XmlUtil;

public class AxisClient {
	static Logger logger = Logger.getLogger(AxisClient.class);
	public static  List<Param> paramList(List<Map<String, String>> params){
		List<Param> paramList = new ArrayList<Param>();
		for (int i = 0; i < params.size(); i++) {
			Param param = new Param();
			Map<String, String> map  = params.get(i);
	        param.setParamName(map.get("name"));
	        param.setParamValue(map.get("value"));
	        param.setParamType(XMLType.XSD_STRING);
	        paramList.add(param);
		}
		return paramList;
	}
    public static void main(String[] args) {
    	AxisClient ac = new AxisClient();
    	ac.getQuoteNo();
//    	ac.insertBillNo();
	}
    
    public  void getQuoteNo(){
    	String request_url="http://210.21.127.254:9081/gdia/ws/search";
    	String request_urllocal="http://localhost:8080/gdia/ws/search";
        logger.debug("投保调用平台URL：" + request_url);
        WebserviceClient aws = new WebserviceClient(request_urllocal);
        List<Map<String, String>> params = new ArrayList<Map<String, String>>();
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("name", "quote");
        map1.put("value", QuoteProcotol.quoteNo("B-001002003-201412040128"));
        params.add(map1);
        List<Param> paramList = AxisClient.paramList(params);
        String methodName = "getquoteno";
        try {
        	logger.debug("报价单查询开始");
			String xmlResult = aws.invoke(methodName, paramList);
			System.out.println(xmlResult);
			XmlUtil util = new XmlUtil(xmlResult);
			logger.debug("报价单："+util.getSingleElementValue("quote-no"));
			logger.debug("投保人："+util.getSingleElementValue("policy-name"));
			logger.debug("消息："+util.getSingleElementValue("message"));
			logger.debug("报价单查询结束");
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    public  void insertBillNo(){
    	String request_url="http://210.21.127.254:9081/gdia/ws/writing";
    	String request_urllocal="http://localhost:8080/gdia/ws/writing";
        logger.debug("投保调用平台URL：" + request_url);
        WebserviceClient aws = new WebserviceClient(request_urllocal);
        List<Map<String, String>> params = new ArrayList<Map<String, String>>();
        Map<String, String> map1 = new HashMap<String, String>();
        map1.put("name", "billQuote");
        map1.put("value", BillProcotol.billQuote("TQBB201132000000000131","B-001001003-201506300205"));
        params.add(map1);
        List<Param> paramList = AxisClient.paramList(params);
        String methodName = "insertbillno";
        try {
        	logger.debug("保单反写开始");
			String xmlResult = aws.invoke(methodName, paramList);
			System.out.println(xmlResult);
			XmlUtil util = new XmlUtil(xmlResult);
			logger.debug("投保单号："+util.getSingleElementValue("bill-no"));
			logger.debug("报价单号："+util.getSingleElementValue("quote-no"));
			logger.debug("传输时间："+util.getSingleElementValue("trans-date"));
			logger.debug("消息："+util.getSingleElementValue("message"));
			logger.debug("保单反写结束");
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
}
